﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class group_class
    {
       // public User u = User.createObj();

        public void Add_group(string email, string _description, int _from, int _to, string dayy1, int numday1, int month1, int year1, string email2, string email3, string email4, string email5)
        {
            SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\elkolyaa\calendar-maintainer-508c42534a4c\calendar-maintainer-508c42534a4c\WindowsFormsApplication1\WindowsFormsApplication1\usersDB.mdf;Integrated Security=True");
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cn.Open();
            calendar c = new calendar();

            string month = month1.ToString(), yearr = year1.ToString() , numday = numday1.ToString() ;

            bool check = c.check_conflect(_from, _to, numday, month, yearr);

            if (check)
            {
                cmd.CommandText = "insert into users (emails,event_desc,event_timefrom,event_timeto,event_day,event_numDay,event_month,event_year ,email2,email3,email4,email5 ) values('" + email + "','" + _description + "','" + _from + "','" + _to + "' , '" + dayy1 + "' , '" + numday1 + "' , '" + month1 + "' , '" + year1 + "' , '" + email2 + "','" + email3 + "', '" + email4 + "','" + email5 + "')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("the event is saved", "database");
            }

            else
                MessageBox.Show("Duplicated data", "Error !! ");
        }
    }
}
